<script setup>
import router from '../router';
import { getCurrentInstance, reactive, ref, onMounted } from 'vue'
const { proxy } = getCurrentInstance();
import { fetchApi } from '../apis/fetchapi'
import { userStore } from '../store/index'
const userSData = userStore();
const userInfo = userSData.userInfo;
import { Swiper, SwiperSlide } from 'swiper/vue';
import { Pagination, Autoplay } from 'swiper/modules';
import 'swiper/css';
import 'swiper/css/pagination'
const modules = [Autoplay, Pagination];
import GoBack from '../components/GoBack.vue'
const onSwiper = (swiper) => {
};
const onSlideChange = () => {
};

function jump(url) {
  if (userSData.loginauth) {
    router.push(url)
  } else {
    router.push('/login')
  }
}

fetchApi('/user-info',).then(res => {
  if (res.code === 200) {
    userSData.setUserInfo({ ...res.data })
  }
})

const activityList = ref([]);
const pageNo = ref(1);
const pageSize = ref(100)
const gameId = ref(0)
const status = ref(0)
// const banner = reactive([])
function getActivity() {
  fetchApi('/act-list', {
    pageNo: pageNo.value,
    pageSize: pageSize.value,
    gameId: gameId.value,
    status: status.value,
  }).then(res => {
    if (res.code === 200) {
      activityList.value = activityList.value.concat(...res.data.list);
    }
  })
}
onMounted(() => {
  getActivity();
  // fetchApi('/recommend').then(res => {
  //   if (res.code === 200) {
  //     banner.value = [...res.data]
  //     console.log(res.data)
  //   }
  // })
})
function toActivity(data) {
  userSData.setActivityData(data);
  router.push({ path: '/recruit', query: { id: data.id } })
}

</script>

<template>
  <div class="indexContainer">
    <GoBack hasUrl="false" title="万代卡玩活动中心"></GoBack>
    <div class="index-con">
      <div class="shop-con">
        <div class="logo">

        </div>
        <div class="shop-info">
          <div class="name"><b>{{ userInfo.schemeType }} </b>{{ userInfo.shopName }}</div>
          <div class="tx">所属体系：{{ userInfo.schemeType }}</div>
          <div class="fzr">负责人：{{ userInfo.connectName }}</div>
        </div>
      </div>
      <div class="swiper-con">
        <swiper :autoplay="{ delay: 4000, disableOnInteraction: false }" :loop="true" :modules="modules"
          :pagination="{ clickable: true }" @swiper="onSwiper" @slideChange="onSlideChange">
          <swiper-slide v-for="item in activityList.slice(0, 3)" @click="toActivity(item)" :key="item.id">
            <img :src="item.picUrl" alt="">
          </swiper-slide>
        </swiper>
      </div>
      <div class="link-btns">
        <div class="to-shop" @click="jump('/activity')">活动管理</div>
        <div class="to-record" @click="jump('/bored')">物料管理</div>
      </div>
      <div class="list-con">
        <div class="m-title">最新活动</div>
        <div class="list">
          <div class="li" v-for="item in activityList" :key="item.id">
            <div class="logo">
              <img :src="item.picUrl" alt="">
            </div>
            <div class="con">
              <div class="title">{{ item.title }}</div>
              <div class="time">活动时间：{{ item.beginTime }}-{{ item.endTime }}</div>
              <div class="btns" v-if="item.status === 1">
                <div class="btn">招募中</div>
                <div class="btn" @click="toActivity(item)">立即申请</div>
              </div>
              <div class="btns" v-else>
                <div class="btn no">已结束</div>
                <div class="btn no" @click="toActivity(item)">立即申请</div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped lang="scss">
@mixin bg($name) {

  background:url(../assets/images/#{$name}.png) no-repeat center top;
  background-size: 100% auto;
}

@mixin wh($w, $h) {
  width:#{$w}px;
  height: #{$h}px;
}


.indexContainer {
  width: 100%;
  overflow: auto;
  height: 100vh;

  .confirm-title {
    font-size: 32px;
    color: rgb(255, 27, 27);
    text-align: center;
    line-height: 60px;
    height: 105px;
  }
}

.index-con {
  margin: 10px auto 0;
  padding-bottom: 50px;
  border-radius: 20px 20px 0 0;
  background: rgb(245, 245, 245);
}

.shop-con {
  width: 345px;
  height: 122px;
  margin: 0 auto 5px;
  position: relative;
  top: -10px;
  background: rgb(203, 36, 50);
  border-radius: 12px;
  display: flex;
  box-sizing: border-box;
  padding: 27px 20px 0;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;

  .shop-info {
    width: 230px;
    margin-bottom: 1px;

    .name b {
      padding-right: 5px;
    }
  }

  .logo {
    width: 48px;
    height: 48px;
    margin-top: 10px;
    background: black;
    margin-right: 18px;
  }

  .name {
    font-size: 14px;
    font-weight: normal;
    height: 20px;
    line-height: 20px;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: rgb(242, 226, 174);
    margin-bottom: 12px;

    b {
      font-size: 16px;
      font-weight: bold;
    }
  }

  .tx {
    font-size: 12px;
    color: rgb(242, 226, 174);
    margin-bottom: 12px;
  }

  .fzr {
    font-size: 12px;
    color: rgb(242, 226, 174);
  }
}

.swiper-con {
  width: 345px;
  height: 146px;
  margin: 0 auto 30px;

  img {
    width: 100%;
    height: 100%;
    display: block;
    margin: auto;
  }

  .swiper {
    height: 100%;
  }

  :deep(.swiper-pagination) .swiper-pagination-bullet.swiper-pagination-bullet-active {
    background-color: rgb(203, 36, 50);
  }

  :deep(.swiper-pagination-bullet) {
    background-color: rgb(220, 220, 220);
    width: 6px;
    height: 6px;
    opacity: 1;
    border-radius: 50%;
  }

}


.link-btns {
  width: 100%;
  height: 92px;
  margin: 0 auto 10px;
  display: flex;
  align-items: center;
  justify-content: center;

  div {
    width: 152px;
    height: 92px;
    border: 1PX solid rgb(187, 187, 187);
    color: #ffffff;
    font-size: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 15px;
    background: rgb(64, 149, 229);

    &+div {
      background: rgb(252, 202, 0);
    }
  }
}

.list-con {
  width: 345px;
  margin: 0 auto;
  border-radius: 12px;
  background: rgb(255, 255, 255);
  box-sizing: border-box;
  padding: 10px 15px 25px;

  .li {
    display: flex;
    align-items: flex-start;
    justify-content: flex-start;
    margin-bottom: 12px;
  }

  .m-title {
    box-sizing: border-box;
    height: 32px;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    color: rgb(16, 16, 16);
    font-size: 16px;
    font-weight: bold;
    margin-bottom: 3px;

    &::before {
      content: "";
      height: 18px;
      width: 1px;
      background: rgb(255, 37, 37);
      display: block;
      margin-right: 8px;
    }
  }

  .logo {
    width: 66px;
    height: 95px;
    background: rgb(22, 130, 254);
    border-radius: 5px;
    overflow: hidden;

    img {
      width: 100%;
      height: 100%;
    }
  }

  .con {
    width: 230px;
    margin-left: 12px;
  }

  .title {
    color: rgb(62, 66, 73);
    font-size: 16px;
    line-height: 24px;
    height: 24px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 100%;
  }

  .time {
    color: rgb(62, 66, 73);
    font-size: 12px;
    line-height: 28px;
    height: 32px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 100%;
    color: rgb(146, 146, 176);
  }

  .btns {
    height: 35px;
    display: flex;
    align-items: flex-start;
    justify-content: flex-start;

    .btn {
      width: 72px;
      height: 35px;
      line-height: 35px;
      border-radius: 2px;
      display: flex;
      color: #ffffff;
      background: rgb(233, 157, 66);
      align-items: center;
      justify-content: center;
      font-size: 14px;
      margin-right: 15px;

      &+.btn {
        background: rgb(255, 191, 51);
      }

      &.no {
        background: rgb(187, 187, 187);
      }

    }
  }
}
</style>